package team.nmsg.ge.system.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import team.nmsg.ge.system.bean.SysUser;
import team.nmsg.ge.system.init.shiro.SysAuthorizingRealm;

public class SysUtil {

	/** 
	* 获得一个UUID 
	* @return String UUID 
	*/ 
	public static String getUUID(){ 
		String uuid = UUID.randomUUID().toString(); 
		//去掉“-”符号 
		return uuid.replaceAll("-", "");
	}
	
	public static String getTimeUID(){
		SimpleDateFormat  dataFormat = new SimpleDateFormat ("yyyyMMddhhmmss");
		String format = dataFormat.format(new Date());
		String randomStr = (int)(Math.random() * 1000) + "";
		int addCount = 3 - randomStr.length();
		String addStr = "";
		for(int i = 0; i < addCount; i++){
			addStr += "0";
		}
		randomStr = addStr + randomStr;
		String timeUid = format + randomStr;
		return timeUid;
	}
	
	public static boolean operatingNotPermit(String createUserId){
//		if(!SysAuthorizingRealm.isAdmin()){
//			SysUser cUser = SysAuthorizingRealm.getCUser();
//			if(cUser.getUserId().intValue() != Integer.parseInt(createUserId) ){
//				return true;
//			}
//		}
		return false;
	}
	
	public static boolean strIsEmpty(String str){
		if(str == null){
			return true;
		}
		if(str.equals("")){
			return true;
		}
		return false;
	}
	public static boolean strIsNotEmpty(String str){
		
		return !strIsEmpty(str);
	}
	
	public static String formatDateWithTime( Date timestamp) {

		if (timestamp == null) {
			return "";
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(timestamp);
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 20; i++) {
			System.out.println(getTimeUID());
			
		}
	}
}
